package com.clouddot.baipai.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.clouddot.baipai.R;


/**
 * Created by wxy on 2018/4/2.
 */

public class A_courseDailog {
    private Dialog Dialog;
    private LinearLayout linearLayout;
    private TextView[] textViews = new TextView[5];
    private Context context;
    private View view;

    public A_courseDailog(Context context) {
        this.context = context;
        initView();

    }


    private void initView() {
        linearLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.a_d_coursedialog, null);
    }

    public TextView[] getTextViews(){
        textViews[0] = linearLayout.findViewById(R.id.CourseName);
        textViews[1] = linearLayout.findViewById(R.id.TeacherName);
        textViews[2] = linearLayout.findViewById(R.id.currentWeek);
        textViews[3] = linearLayout.findViewById(R.id.WeekHours);
        textViews[4] = linearLayout.findViewById(R.id.Remark);
        return textViews;
    }

    public void showDialog() {

        Dialog = getDialog();
        Dialog.show();

    }

    public void closeDialog() {
        if (Dialog != null)
        {
            Dialog.dismiss();
        }
    }

    public Dialog getDialog() {
        if (Dialog == null)
        {
            Dialog = new Dialog(context,R.style.ActionDialogStyle);
        }

        Dialog.setContentView(linearLayout);

        Window dialogWindow = Dialog.getWindow();

        view = dialogWindow.getDecorView();
        lock();

        view.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int i) {
                lock();
            }
        });

        dialogWindow.setGravity( Gravity.CENTER);

        WindowManager.LayoutParams lp = dialogWindow.getAttributes();

        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;

        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;


        dialogWindow.setAttributes(lp);

        Dialog.setCancelable(true);

        return Dialog;
    }
    private void lock(){
        int uiFlags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE;
        view.setSystemUiVisibility(uiFlags);
    }


}



